package com.xuanyuan.test

import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.widget.Toast
import androidx.appcompat.app.AppCompatActivity
import com.xuanyuan.material.R
import com.zhy.view.flowlayout.TagFlowLayout

class TestActivity : AppCompatActivity(), com.zhy.view.flowlayout.ItemLongClickListener {

    private val mVals = arrayOf(
        "Hello", "Android", "Weclome Hi ", "Button", "TextView", "Hello",
        "Android", "Weclome", "Button ImageView", "TextView", "Helloworld",
        "Android", "Weclome Hello", "Button Text", "TextView"
    )

    private var mFlowLayout: TagFlowLayout? = null
    var isShowDelete = false
    var tagSearchAdapter: TagSearchAdapter<String>? = null

    lateinit var mInflater: LayoutInflater

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_test)
        isShowDelete

         mInflater = LayoutInflater.from(this)

        mFlowLayout = findViewById<View>(R.id.id_flowlayout) as TagFlowLayout
        mFlowLayout?.setOnClickListener {
            Toast.makeText(this, "FlowLayout Clicked", Toast.LENGTH_SHORT).show()
        }
        initAdapter()

    }

    private fun initAdapter() {
        mFlowLayout?.let {
            tagSearchAdapter = TagSearchAdapter<String>(mInflater, isShowDelete, it, mVals)
            it.adapter = tagSearchAdapter
            it.setItemLongClickListener(this)
        }
    }


    override fun onItemLongClick(position: Int, t: String?) {
        isShowDelete = !isShowDelete
        tagSearchAdapter = null
        initAdapter()

    }
}
